package com.rongzhe.house.presenter;

import android.content.Intent;

import com.rongzhe.house.entity.LifeServiceBanner;
import com.rongzhe.house.internet.DataListener;
import com.rongzhe.house.manager.BannerManager;
import com.rongzhe.house.ui.UiControlInterface;
import com.rongzhe.house.ui.activity.LifeServiceActivity;

import java.util.List;

/**
 * Created by huang on 2017/12/14.
 */

public class LifeServicePresenter extends BasePresenter {
    public LifeServicePresenter(UiControlInterface uiControlInterface) {
        super(uiControlInterface);
    }

    @Override
    public void start(Intent intent) {
        int banners[] = {LifeServiceBanner.Companion.getHouseMoving(),
                LifeServiceBanner.Companion.getCleaning(),
                LifeServiceBanner.Companion.getRepair()};
        for (int i = 0; i < banners.length; i++) {
            loadBanner(banners[i]);
        }
    }

    private void loadBanner(final int type) {
        BannerManager.getInstance().getBannersLifeService(
                LifeServiceBanner.Companion.getHouseMoving(),
                new DataListener<List<LifeServiceBanner>>() {
                    @Override
                    public void onSuccess(List<LifeServiceBanner> data, String message) {
                        ((LifeServiceActivity)getUiControlInterface()).setHouseMovingData(type, data);
                    }

                    @Override
                    public void onFailed(Throwable error, String message) {
                        getUiControlInterface().showToast(message);
                    }

                    @Override
                    public void onEnd() {

                    }
                });
    }

}
